package org.shj.hadoop.customerinputformat;

import java.io.IOException;

import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class FindMaxValueReduce extends Reducer<IntWritable, FloatWritable, Text, FloatWritable>{

	public void reduce(IntWritable key, Iterable<FloatWritable> values, Context context) throws IOException, InterruptedException{
		java.util.Iterator<FloatWritable> it = values.iterator();
		float max = 0, tmp;
		if(it.hasNext()){
			max = it.next().get();
		}else{
			context.write(new Text("Max float value: "), null);
			return;
		}
		
		while(it.hasNext()){
			tmp = it.next().get();
			if(tmp > max){
				max = tmp;
			}
		}
		
		context.write(new Text("Max float value: "), new FloatWritable(max));
	}
}
